package handlers

import (
	"film-hub/models"
	"github.com/gin-gonic/gin"
)

func Add(c *gin.Context) {
	title := c.PostForm("title")
	comment := c.PostForm("comment")
	author := c.PostForm("author")

	if title == "" || comment == "" || author == "" {
		c.JSON(200, gin.H{
			"code": 500,
			"msg":  "字段不能为空",
		})
		return
	}
	data := models.Film{
		Title:   title,
		Comment: comment,
		Author:  author,
	}
	models.DB.Create(&data)
	c.JSON(200, gin.H{
		"code": 200,
		"msg":  "添加成功",
	})
	return
}
func List(c *gin.Context) {
	var film []models.Film
	models.DB.Find(&film)
	c.JSON(200, gin.H{
		"code": 200,
		"msg":  "ok",
		"data": film,
	})
	return
}
